# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=pantry
pkgname=haskell-pantry
pkgver=0.5.7
pkgrel=185
pkgdesc="Content addressable Haskell package management"
url="https://github.com/commercialhaskell/pantry"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-ansi-terminal' 'haskell-casa-client'
         'haskell-casa-types' 'haskell-conduit' 'haskell-conduit-extra' 'haskell-crypton'
         'haskell-crypton-conduit' 'haskell-digest' 'haskell-filelock' 'haskell-generic-deriving'
         'haskell-hackage-security' 'haskell-hpack' 'haskell-http-client' 'haskell-http-client-tls'
         'haskell-http-conduit' 'haskell-http-download' 'haskell-http-types' 'haskell-memory'
         'haskell-mono-traversable' 'haskell-network-uri' 'haskell-path' 'haskell-path-io'
         'haskell-persistent' 'haskell-persistent-sqlite' 'haskell-primitive' 'haskell-resourcet'
         'haskell-rio' 'haskell-rio-orphans' 'haskell-rio-prettyprint' 'haskell-tar-conduit'
         'haskell-text-metrics' 'haskell-unix-compat' 'haskell-unliftio'
         'haskell-unordered-containers' 'haskell-vector' 'haskell-yaml' 'haskell-zip-archive')
makedepends=('ghc' 'uusi' 'haskell-hedgehog' 'haskell-hspec' 'haskell-quickcheck'
             'haskell-raw-strings-qq')
checkdepends=('git' 'mercurial')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('05814d404f97873939e29f183cd74d2c8e6bf5b3e87a9c665694578faeab641d9b8d3efef0525727a881031a5bf815e39299388ce0207d5ef04c674f172e7618')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
    uusi -d persistent-template -r cryptonite:crypton -r cryptonite-conduit:crypton-conduit $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    LANG=en_US.UTF-8 runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
